﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true"
    CodeBehind="List.aspx.cs" Inherits="jnxc.Web.addHappen.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Script/username.js"></script>
    <script src="../Script/datetime.js"></script>
    <script type="text/javascript">

        $(function () {
            InitGird();
            InitSearch();
        });
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '发生表', //表格标题
                url: 'HappenMAN.ashx', //请求数据的页面
                sortName: 'addhappen_id', //排序字段
                idField: 'addhappen_id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
               // height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
					{ field: 'ckb', checkbox: true },
                    { title: '年度', field: 'nd', width: 150 },
                    { title: '月份', field: 'yf', width: 150 },
					{ title: '区域代码', field: 'abh', width: 150, sortable: true },
					{ title: '区域名称', field: 'aname', width: 150 },
					{ title: '病虫名称', field: 'dpname', width: 150 },
					{ title: '寄主名称', field: 'trees', width: 150 },
					{
					    title: '调查时间', field: 'dctime', width: 150, formatter: function (value, row, index) {
					        if (value != "") {
					            if (value.indexOf("-") != -1) {
					                value = value.replace(/-/g, "/")
					            }
					            return new Date(value).pattern("yyyy年M月d日");
					        }
					    }
					},
                    
				]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
            $('#aid').combobox({
                url: '../areainfo/GetArea.ashx?action=ddllist',
                valueField: 'aid',
                textField: 'aname',
                panelHeight: 'auto',
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#aid').combobox('getData');
                    $("#aid").combobox('select', data[0].caid);
                }
            });
            $('#dpid').combobox({
                url: '../dpinfo/GetDP.ashx?action=ddllist',
                valueField: 'dpid',
                textField: 'dpname',
                panelHeight: 'auto',
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#dpid').combobox('getData');
                    $("#dpid").combobox('select', data[0].caid);
                }
            });
        }


        function newUser() {
            //清空内容  
            $('#fm').form('clear');
            //加载工作人员的姓名和权限 


            $('#dlg').dialog('open').dialog('setTitle', '发生情况添加');
            document.getElementById("test").value = "add";
        }

        //修改管理员  
        function editUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }


            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改防治');
                $('#apid').val(row.apid);
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');

            if (test == "add") {
                f.form('submit', {
                    url: "HappenMAN.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {
                $('#fm').form('submit', {
                    url: "HappenMAN.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }
        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'HappenMAN.ashx?addhappen_id=' + row.addhappen_id + "&action=" + test,
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    //alert('恭喜您，信息删除成功！')  
                                    // close the dialog  
                                    $('#tt').datagrid('reload');
                                    //$('#fm').form('submit');

                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

    </script>
    <style type="text/css">
        .fitem
        {
            width: 260px;
            float: left;
        }
        .fitem label
        {
            width: 170px;
            line-height: 22px;
        }
        .fitem input
        {
            width: 80px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td style="padding-left: 2px">
                    <a href="#" onclick="newUser();" id="a_add" class="easyui-linkbutton" iconcls="icon-add">
                        添加</a> <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton"
                            data-options="iconCls:'icon-edit'">修改</a> <a href="#" onclick="removeUser();return false;"
                                id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>
                </td>
                <td style="text-align: right; padding-right: 15px">
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            用户名
                        </div>
                        <div name="username">
                            姓 名
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 1150px; height: 500px; overflow: auto;
        padding: 10px 20px" data-options="closed:true,buttons:'#dlg-buttons',shadow:false,resizable: true,maximizable:true,">
        <form id="fm" method="post">
        <div class="fitem">
            <label>
                病虫名称：</label>
            <input id="dpid" name="dpid" class="easyui-combobox" data-options="required:true" />
        </div>
        <div class="fitem">
            <label>
                寄主树种：</label>
            <input id="trees" name="trees" class="easyui-validatebox" data-options="required:true" />
        </div>
        <div class="fitem">
            <label>
                应监面积：</label>
            <input id="yjarea" name="yjarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                区划名称：</label>
            <input id="aid" name="aid" class="easyui-combobox" data-options="required:true" />
        </div>
        <div class="fitem">
            <label>
                寄主面积：</label>
            <input id="jzarea" name="jzarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                监测面积：</label>
            <input id="jcarea" name="jcarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                世代、次：</label>
            <input id="generation" name="generation" class="easyui-validatebox" data-options="required:true,validType:'number'" />
        </div>
        <div class="fitem">
            <label>
                调查时间：</label>
            <input id="dctime" name="dctime" class="easyui-datebox" data-options="required:true" />
        </div>
        <div class="fitem">
            <label>
                低虫口低感病面积：</label>
            <input id="dckdgarea" name="dckdgarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                分布面积：</label>
            <input id="fbarea" name="fbarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                监测覆盖率：</label>
            <input id="jcfgarea" name="jcfgarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
            </label>
        </div>
        <div class="fitem">
            <label>
                发生情况：</label>
        </div>
        <div class="fitem">
            <label>
            </label>
        </div>
        <div class="fitem">
            <label>
            </label>
        </div>
        <div class="fitem">
            <label>
            </label>
        </div>
        <div class="fitem">
            <label>
                世代（次）发生面积：</label>
            <input id="generationfsarea" name="generationfsarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                累计轻度：</label>
            <input id="ljqd" name="ljqd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                累计中度：</label>
            <input id="ljzd" name="ljzd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                累计重度：</label>
            <input id="ljzzd" name="ljzzd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                发生合计（新发生或新扩散）：</label>
            <input id="fshj" name="fshj" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                发生轻度：</label>
            <input id="fsqd" name="fsqd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                发生中度：</label>
            <input id="fszd" name="fszd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                发生重度：</label>
            <input id="fszzd" name="fszzd" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                同病虫新发生：</label>
            <input id="tbcxfs" name="tbcxfs" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                发生率%：</label>
            <input id="fsl" name="fsl" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
        </div>
        <div class="fitem">
            <label>
                预计成灾面积：</label>
            <input id="yjczarea" name="yjczarea" class="easyui-validatebox" data-options="validType:'floatOrInt'" />
            <input name="Test" id="test" type="hidden" />
            <input name="addhappen_id" id="addhappen_id" type="hidden" />
            <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
        </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">
            保存</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
</asp:Content>
